﻿namespace BreezeExtension.VSPackage.Package
{
    using System;
    using System.ComponentModel.Design;
    using System.Runtime.InteropServices;
    using Forms;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.Shell.Interop;

    // Tells the createpkgdef.exe that this class is a package
    [PackageRegistration(UseManagedResourcesOnly = true)]

    // This lets the shell know that some menus will be created.
    [ProvideMenuResource("Menus.ctmenu", 1)]

    [Guid(GuidList.guidBreezeExtension_VSPackagePkgString)]

    public sealed class BreezePackage : Package
    {
        /// <summary>
        /// You can place initialisation code here that does not require a Visual Studio service.
        /// At the construction phase the class is being created but not sited inside Visual Studio.
        /// </summary>
        public BreezePackage()
        {
        }

        /// <summary>
        /// This is called when the package is sited in Visual Studio and so as such can perform
        /// initialisation actions that require Visual Studio services.
        /// </summary>
        protected override void Initialize()
        {
            // In the template this is called first, I assume this is convention.
            base.Initialize();

            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if(mcs != null)
            {
                var menuCommandID = new CommandID(GuidList.guidBreezeExtension_VSPackageCmdSet, (int)PkgCmdIDList.cmdidAddDomainModule);
                var menuItem = new MenuCommand(AddDomainModule, menuCommandID );

                mcs.AddCommand(menuItem);
            }
        }

        private void AddDomainModule(object sender, EventArgs args)
        {
            AddDomainModule addDomainForm = new AddDomainModule();
            addDomainForm.ShowDialog();
            string userProvidedFileName = addDomainForm.DomainModuleName;

            // Accesses the Visual Studio services by interface. This is central to VSPackages.
            var projectService = GetService(typeof(IVsProject3)) as IVsProject3;

            //projectService.AddItem((uint)VSConstants.VSITEMID.Root, VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE, userProvidedFileName, 1, )
        }
    }
}
